package top.leyi.ServiceImpl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import top.leyi.IService.IClassService;
import top.leyi.entity.Class;
import top.leyi.entity.College;
import top.leyi.mapper.ClassMapper;

import java.util.List;

@Service("Class")
public class ClassServiceImpl implements IClassService {

    @Autowired
    ClassMapper classMapper;

    @Override
    public void addOneClass() {

    }

    public int queryClass(Class clazz) {
        return classMapper.queryClass(clazz);
    }


    @Override
    public Class queryClass(int userId) {
        return classMapper.queryClassData(userId);
    }

    /**
     * @descripe 查询所有班级
     * @return
     */
    @Override
    @Transactional
    public List<College> queryAllClass() {
        List<College> collegeList = classMapper.queryAllCollege();
        for(College college : collegeList){
            college.setClasses(classMapper.queryAllClassWithCol(college.getId()));
        }
        return collegeList;
    }
}
